import Cookies from 'js-cookie'

const TOKEN_KEY = 'car_auth_token'
const TOKEN_EXPIRES = 7 // days

/**
 * Get authentication token from cookies
 */
export function getToken(): string | null {
  return Cookies.get(TOKEN_KEY) || null
}

/**
 * Set authentication token in cookies
 */
export function setToken(token: string): void {
  Cookies.set(TOKEN_KEY, token, { expires: TOKEN_EXPIRES })
}

/**
 * Remove authentication token from cookies
 */
export function removeToken(): void {
  Cookies.remove(TOKEN_KEY)
}

/**
 * Check if user is authenticated
 */
export function isAuthenticated(): boolean {
  return !!getToken()
}

/**
 * Get authorization header for API requests
 */
export function getAuthHeader(): Record<string, string> {
  const token = getToken()
  return token ? { Authorization: `Bearer ${token}` } : {}
}